package config

import "github.com/saint-yellow/go-pl/toys/gohub/pkg/config"

func init() {

    config.Add("database", func() map[string]interface{} {
        return map[string]interface{}{

            // 默认数据库
            "connection": config.Env("DB_CONNECTION", "postgresql"),

            "mysql": map[string]interface{}{

                // 数据库连接信息
                "host":     config.Env("MYSQL_HOST", "127.0.0.1"),
                "port":     config.Env("MYSQL_PORT", "3306"),
                "database": config.Env("MYSQL_DATABASE", "gohub"),
                "username": config.Env("MYSQL_USERNAME", ""),
                "password": config.Env("MYSQL_PASSWORD", ""),
                "charset":  "utf8mb4",

                // 连接池配置
                "max_idle_connections": config.Env("DB_MAX_IDLE_CONNECTIONS", 100),
                "max_open_connections": config.Env("DB_MAX_OPEN_CONNECTIONS", 25),
                "max_life_seconds":     config.Env("DB_MAX_LIFE_SECONDS", 5*60),
            },

            "postgresql": map[string]interface{}{
                // 数据库连接信息
                "host":     config.Env("POSTGRESQL_HOST", "127.0.0.1"),
                "port":     config.Env("POSTGRESQL_PORT", "5432"),
                "database": config.Env("POSTGRESQL_DATABASE", "gohub"),
                "username": config.Env("POSTGRESQL_USERNAME", ""),
                "password": config.Env("POSTGRESQL_PASSWORD", ""),

                // 连接池配置
                "max_idle_connections": config.Env("DB_MAX_IDLE_CONNECTIONS", 100),
                "max_open_connections": config.Env("DB_MAX_OPEN_CONNECTIONS", 25),
                "max_life_seconds":     config.Env("DB_MAX_LIFE_SECONDS", 5*60),
            },

            "sqlite": map[string]interface{}{
                "database": config.Env("DB_SQL_FILE", "database/database.db"),
            },
        }
    })
}
